package com.dxf.chepter04

/**
 * 抽象:
 * 定义一个类,把一个事务共有的属性和行为提取出来形成一个物理模板,这种研究问题的方法称为抽象
 *
 *
 *
 *
 *
 *
 */

//对象中的方法都是静态的
object T54_面向对象继承_封装_多态 {
  def main(args: Array[String]): Unit = {
    val account = new Account("gh00001", 890.4, "1")
    account.query("1")

    account.withDraw("1", 100)

    account.query("1")

    printLine

  }


}

class Account(inAccount: String, inBalance: BigDecimal = 0.0, inPwd: String) {
  val accountNo = inAccount
  private var balance = inBalance
  private var pwd = inPwd

  def this(account: String, pwd: String) {
    this(account, inPwd = pwd)
  }

  //c查询
  def query(pwd: String): Unit = {
    if (!this.pwd.equals(pwd)) {
      println("密码错误")
      return
    }

    println("account=" + accountNo + " balance=" + balance)
  }


  def withDraw(pwd: String, money: BigDecimal): Any = {
    if (!this.pwd.equals(pwd)) {
      println("密码错误")
      return
    }
    if (this.balance < money) {
      println("余额不足")
      return
    }
    this.balance -= money
    return money

  }


}



